home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch12 / Styles2D.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-06-18  |  38.2 KB  |  1,168 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form frmStyles2D 
  4.    Caption         =   "Styles2D"
  5.    ClientHeight    =   5190
  6.    ClientLeft      =   825
  7.    ClientTop       =   1740
  8.    ClientWidth     =   8685
  9.    LinkTopic       =   "Form1"
  10.    PaletteMode     =   1  'UseZOrder
  11.    ScaleHeight     =   5190
  12.    ScaleWidth      =   8685
  13.    Begin VB.TextBox txtYStretch 
  14.       Height          =   285
  15.       Left            =   2520
  16.       TabIndex        =   50
  17.       Text            =   "1.0"
  18.       Top             =   480
  19.       Width           =   615
  20.    End
  21.    Begin VB.TextBox txtXStretch 
  22.       Height          =   285
  23.       Left            =   2520
  24.       TabIndex        =   48
  25.       Text            =   "1.0"
  26.       Top             =   120
  27.       Width           =   615
  28.    End
  29.    Begin VB.TextBox txtRotation 
  30.       Height          =   285
  31.       Left            =   840
  32.       TabIndex        =   46
  33.       Text            =   "0.0"
  34.       Top             =   480
  35.       Width           =   615
  36.    End
  37.    Begin MSComDlg.CommonDialog dlgFile 
  38.       Left            =   5280
  39.       Top             =   120
  40.       _ExtentX        =   847
  41.       _ExtentY        =   847
  42.       _Version        =   393216
  43.    End
  44.    Begin VB.Frame Frame2 
  45.       Caption         =   "ForeColor"
  46.       Height          =   1575
  47.       Index           =   1
  48.       Left            =   0
  49.       TabIndex        =   30
  50.       Top             =   1200
  51.       Width           =   2295
  52.       Begin VB.OptionButton optForeColor 
  53.          Caption         =   "Cyan"
  54.          BeginProperty Font 
  55.             Name            =   "MS Sans Serif"
  56.             Size            =   8.25
  57.             Charset         =   0
  58.             Weight          =   700
  59.             Underline       =   0   'False
  60.             Italic          =   0   'False
  61.             Strikethrough   =   0   'False
  62.          EndProperty
  63.          ForeColor       =   &H00FF00FF&
  64.          Height          =   255
  65.          Index           =   9
  66.          Left            =   1080
  67.          TabIndex        =   40
  68.          Top             =   1200
  69.          Width           =   855
  70.       End
  71.       Begin VB.OptionButton optForeColor 
  72.          Caption         =   "Yellow"
  73.          BeginProperty Font 
  74.             Name            =   "MS Sans Serif"
  75.             Size            =   8.25
  76.             Charset         =   0
  77.             Weight          =   700
  78.             Underline       =   0   'False
  79.             Italic          =   0   'False
  80.             Strikethrough   =   0   'False
  81.          EndProperty
  82.          ForeColor       =   &H0000FFFF&
  83.          Height          =   255
  84.          Index           =   5
  85.          Left            =   1080
  86.          TabIndex        =   39
  87.          Top             =   240
  88.          Width           =   975
  89.       End
  90.       Begin VB.OptionButton optForeColor 
  91.          Caption         =   "Orange"
  92.          BeginProperty Font 
  93.             Name            =   "MS Sans Serif"
  94.             Size            =   8.25
  95.             Charset         =   0
  96.             Weight          =   700
  97.             Underline       =   0   'False
  98.             Italic          =   0   'False
  99.             Strikethrough   =   0   'False
  100.          EndProperty
  101.          ForeColor       =   &H000080FF&
  102.          Height          =   255
  103.          Index           =   6
  104.          Left            =   1080
  105.          TabIndex        =   38
  106.          Top             =   480
  107.          Width           =   975
  108.       End
  109.       Begin VB.OptionButton optForeColor 
  110.          Caption         =   "Lt Green"
  111.          BeginProperty Font 
  112.             Name            =   "MS Sans Serif"
  113.             Size            =   8.25
  114.             Charset         =   0
  115.             Weight          =   700
  116.             Underline       =   0   'False
  117.             Italic          =   0   'False
  118.             Strikethrough   =   0   'False
  119.          EndProperty
  120.          ForeColor       =   &H00C0FFC0&
  121.          Height          =   255
  122.          Index           =   7
  123.          Left            =   1080
  124.          TabIndex        =   37
  125.          Top             =   720
  126.          Width           =   1095
  127.       End
  128.       Begin VB.OptionButton optForeColor 
  129.          Caption         =   "Lt Blue"
  130.          BeginProperty Font 
  131.             Name            =   "MS Sans Serif"
  132.             Size            =   8.25
  133.             Charset         =   0
  134.             Weight          =   700
  135.             Underline       =   0   'False
  136.             Italic          =   0   'False
  137.             Strikethrough   =   0   'False
  138.          EndProperty
  139.          ForeColor       =   &H00FFFF00&
  140.          Height          =   255
  141.          Index           =   8
  142.          Left            =   1080
  143.          TabIndex        =   36
  144.          Top             =   960
  145.          Width           =   975
  146.       End
  147.       Begin VB.OptionButton optForeColor 
  148.          Caption         =   "Red"
  149.          BeginProperty Font 
  150.             Name            =   "MS Sans Serif"
  151.             Size            =   8.25
  152.             Charset         =   0
  153.             Weight          =   700
  154.             Underline       =   0   'False
  155.             Italic          =   0   'False
  156.             Strikethrough   =   0   'False
  157.          EndProperty
  158.          ForeColor       =   &H000000FF&
  159.          Height          =   255
  160.          Index           =   1
  161.          Left            =   120
  162.          TabIndex        =   35
  163.          Top             =   480
  164.          Width           =   855
  165.       End
  166.       Begin VB.OptionButton optForeColor 
  167.          Caption         =   "Green"
  168.          BeginProperty Font 
  169.             Name            =   "MS Sans Serif"
  170.             Size            =   8.25
  171.             Charset         =   0
  172.             Weight          =   700
  173.             Underline       =   0   'False
  174.             Italic          =   0   'False
  175.             Strikethrough   =   0   'False
  176.          EndProperty
  177.          ForeColor       =   &H0000FF00&
  178.          Height          =   255
  179.          Index           =   2
  180.          Left            =   120
  181.          TabIndex        =   34
  182.          Top             =   720
  183.          Width           =   855
  184.       End
  185.       Begin VB.OptionButton optForeColor 
  186.          Caption         =   "Blue"
  187.          BeginProperty Font 
  188.             Name            =   "MS Sans Serif"
  189.             Size            =   8.25
  190.             Charset         =   0
  191.             Weight          =   700
  192.             Underline       =   0   'False
  193.             Italic          =   0   'False
  194.             Strikethrough   =   0   'False
  195.          EndProperty
  196.          ForeColor       =   &H00FF0000&
  197.          Height          =   255
  198.          Index           =   3
  199.          Left            =   120
  200.          TabIndex        =   33
  201.          Top             =   960
  202.          Width           =   855
  203.       End
  204.       Begin VB.OptionButton optForeColor 
  205.          Caption         =   "Black"
  206.          BeginProperty Font 
  207.             Name            =   "MS Sans Serif"
  208.             Size            =   8.25
  209.             Charset         =   0
  210.             Weight          =   700
  211.             Underline       =   0   'False
  212.             Italic          =   0   'False
  213.             Strikethrough   =   0   'False
  214.          EndProperty
  215.          ForeColor       =   &H00000000&
  216.          Height          =   255
  217.          Index           =   0
  218.          Left            =   120
  219.          TabIndex        =   32
  220.          Top             =   240
  221.          Width           =   855
  222.       End
  223.       Begin VB.OptionButton optForeColor 
  224.          Caption         =   "White"
  225.          BeginProperty Font 
  226.             Name            =   "MS Sans Serif"
  227.             Size            =   8.25
  228.             Charset         =   0
  229.             Weight          =   700
  230.             Underline       =   0   'False
  231.             Italic          =   0   'False
  232.             Strikethrough   =   0   'False
  233.          EndProperty
  234.          ForeColor       =   &H00FFFFFF&
  235.          Height          =   255
  236.          Index           =   4
  237.          Left            =   120
  238.          TabIndex        =   31
  239.          Top             =   1200
  240.          Width           =   855
  241.       End
  242.    End
  243.    Begin VB.Frame Frame2 
  244.       Caption         =   "FillColor"
  245.       Height          =   1575
  246.       Index           =   0
  247.       Left            =   2400
  248.       TabIndex        =   24
  249.       Top             =   1200
  250.       Width           =   2295
  251.       Begin VB.OptionButton optFillColor 
  252.          Caption         =   "Lt Blue"
  253.          BeginProperty Font 
  254.             Name            =   "MS Sans Serif"
  255.             Size            =   8.25
  256.             Charset         =   0
  257.             Weight          =   700
  258.             Underline       =   0   'False
  259.             Italic          =   0   'False
  260.             Strikethrough   =   0   'False
  261.          EndProperty
  262.          ForeColor       =   &H00FFFF00&
  263.          Height          =   255
  264.          Index           =   8
  265.          Left            =   1080
  266.          TabIndex        =   45
  267.          Top             =   960
  268.          Width           =   1095
  269.       End
  270.       Begin VB.OptionButton optFillColor 
  271.          Caption         =   "Lt Green"
  272.          BeginProperty Font 
  273.             Name            =   "MS Sans Serif"
  274.             Size            =   8.25
  275.             Charset         =   0
  276.             Weight          =   700
  277.             Underline       =   0   'False
  278.             Italic          =   0   'False
  279.             Strikethrough   =   0   'False
  280.          EndProperty
  281.          ForeColor       =   &H00C0FFC0&
  282.          Height          =   255
  283.          Index           =   7
  284.          Left            =   1080
  285.          TabIndex        =   44
  286.          Top             =   720
  287.          Width           =   1095
  288.       End
  289.       Begin VB.OptionButton optFillColor 
  290.          Caption         =   "Orange"
  291.          BeginProperty Font 
  292.             Name            =   "MS Sans Serif"
  293.             Size            =   8.25
  294.             Charset         =   0
  295.             Weight          =   700
  296.             Underline       =   0   'False
  297.             Italic          =   0   'False
  298.             Strikethrough   =   0   'False
  299.          EndProperty
  300.          ForeColor       =   &H000080FF&
  301.          Height          =   255
  302.          Index           =   6
  303.          Left            =   1080
  304.          TabIndex        =   43
  305.          Top             =   480
  306.          Width           =   1095
  307.       End
  308.       Begin VB.OptionButton optFillColor 
  309.          Caption         =   "Yellow"
  310.          BeginProperty Font 
  311.             Name            =   "MS Sans Serif"
  312.             Size            =   8.25
  313.             Charset         =   0
  314.             Weight          =   700
  315.             Underline       =   0   'False
  316.             Italic          =   0   'False
  317.             Strikethrough   =   0   'False
  318.          EndProperty
  319.          ForeColor       =   &H0000FFFF&
  320.          Height          =   255
  321.          Index           =   5
  322.          Left            =   1080
  323.          TabIndex        =   42
  324.          Top             =   240
  325.          Width           =   1095
  326.       End
  327.       Begin VB.OptionButton optFillColor 
  328.          Caption         =   "Cyan"
  329.          BeginProperty Font 
  330.             Name            =   "MS Sans Serif"
  331.             Size            =   8.25
  332.             Charset         =   0
  333.             Weight          =   700
  334.             Underline       =   0   'False
  335.             Italic          =   0   'False
  336.             Strikethrough   =   0   'False
  337.          EndProperty
  338.          ForeColor       =   &H00FF00FF&
  339.          Height          =   255
  340.          Index           =   9
  341.          Left            =   1080
  342.          TabIndex        =   41
  343.          Top             =   1200
  344.          Width           =   1095
  345.       End
  346.       Begin VB.OptionButton optFillColor 
  347.          Caption         =   "White"
  348.          BeginProperty Font 
  349.             Name            =   "MS Sans Serif"
  350.             Size            =   8.25
  351.             Charset         =   0
  352.             Weight          =   700
  353.             Underline       =   0   'False
  354.             Italic          =   0   'False
  355.             Strikethrough   =   0   'False
  356.          EndProperty
  357.          ForeColor       =   &H00FFFFFF&
  358.          Height          =   255
  359.          Index           =   4
  360.          Left            =   120
  361.          TabIndex        =   29
  362.          Top             =   1200
  363.          Width           =   855
  364.       End
  365.       Begin VB.OptionButton optFillColor 
  366.          Caption         =   "Black"
  367.          BeginProperty Font 
  368.             Name            =   "MS Sans Serif"
  369.             Size            =   8.25
  370.             Charset         =   0
  371.             Weight          =   700
  372.             Underline       =   0   'False
  373.             Italic          =   0   'False
  374.             Strikethrough   =   0   'False
  375.          EndProperty
  376.          ForeColor       =   &H00000000&
  377.          Height          =   255
  378.          Index           =   0
  379.          Left            =   120
  380.          TabIndex        =   28
  381.          Top             =   240
  382.          Width           =   855
  383.       End
  384.       Begin VB.OptionButton optFillColor 
  385.          Caption         =   "Blue"
  386.          BeginProperty Font 
  387.             Name            =   "MS Sans Serif"
  388.             Size            =   8.25
  389.             Charset         =   0
  390.             Weight          =   700
  391.             Underline       =   0   'False
  392.             Italic          =   0   'False
  393.             Strikethrough   =   0   'False
  394.          EndProperty
  395.          ForeColor       =   &H00FF0000&
  396.          Height          =   255
  397.          Index           =   3
  398.          Left            =   120
  399.          TabIndex        =   27
  400.          Top             =   960
  401.          Width           =   855
  402.       End
  403.       Begin VB.OptionButton optFillColor 
  404.          Caption         =   "Green"
  405.          BeginProperty Font 
  406.             Name            =   "MS Sans Serif"
  407.             Size            =   8.25
  408.             Charset         =   0
  409.             Weight          =   700
  410.             Underline       =   0   'False
  411.             Italic          =   0   'False
  412.             Strikethrough   =   0   'False
  413.          EndProperty
  414.          ForeColor       =   &H0000FF00&
  415.          Height          =   255
  416.          Index           =   2
  417.          Left            =   120
  418.          TabIndex        =   26
  419.          Top             =   720
  420.          Width           =   855
  421.       End
  422.       Begin VB.OptionButton optFillColor 
  423.          Caption         =   "Red"
  424.          BeginProperty Font 
  425.             Name            =   "MS Sans Serif"
  426.             Size            =   8.25
  427.             Charset         =   0
  428.             Weight          =   700
  429.             Underline       =   0   'False
  430.             Italic          =   0   'False
  431.             Strikethrough   =   0   'False
  432.          EndProperty
  433.          ForeColor       =   &H000000FF&
  434.          Height          =   255
  435.          Index           =   1
  436.          Left            =   120
  437.          TabIndex        =   25
  438.          Top             =   480
  439.          Width           =   855
  440.       End
  441.    End
  442.    Begin VB.Frame Frame1 
  443.       Caption         =   "FillStyle"
  444.       Height          =   2295
  445.       Index           =   2
  446.       Left            =   2400
  447.       TabIndex        =   15
  448.       Top             =   2880
  449.       Width           =   2295
  450.       Begin VB.OptionButton optFillStyle 
  451.          Caption         =   "vbDiagonalCross"
  452.          Height          =   255
  453.          Index           =   7
  454.          Left            =   120
  455.          TabIndex        =   23
  456.          Top             =   1920
  457.          Width           =   1850
  458.       End
  459.       Begin VB.OptionButton optFillStyle 
  460.          Caption         =   "vbFSSolid"
  461.          Height          =   255
  462.          Index           =   0
  463.          Left            =   120
  464.          TabIndex        =   22
  465.          Top             =   240
  466.          Width           =   1850
  467.       End
  468.       Begin VB.OptionButton optFillStyle 
  469.          Caption         =   "vbFSTransparent"
  470.          Height          =   255
  471.          Index           =   1
  472.          Left            =   120
  473.          TabIndex        =   21
  474.          Top             =   480
  475.          Width           =   1850
  476.       End
  477.       Begin VB.OptionButton optFillStyle 
  478.          Caption         =   "vbHorizontalLine"
  479.          Height          =   255
  480.          Index           =   2
  481.          Left            =   120
  482.          TabIndex        =   20
  483.          Top             =   720
  484.          Width           =   1850
  485.       End
  486.       Begin VB.OptionButton optFillStyle 
  487.          Caption         =   "vbVerticalLine"
  488.          Height          =   255
  489.          Index           =   3
  490.          Left            =   120
  491.          TabIndex        =   19
  492.          Top             =   960
  493.          Width           =   1850
  494.       End
  495.       Begin VB.OptionButton optFillStyle 
  496.          Caption         =   "vbUpwardDiagonal"
  497.          Height          =   255
  498.          Index           =   4
  499.          Left            =   120
  500.          TabIndex        =   18
  501.          Top             =   1200
  502.          Width           =   1850
  503.       End
  504.       Begin VB.OptionButton optFillStyle 
  505.          Caption         =   "vbCross"
  506.          Height          =   255
  507.          Index           =   6
  508.          Left            =   120
  509.          TabIndex        =   16
  510.          Top             =   1680
  511.          Width           =   1850
  512.       End
  513.       Begin VB.OptionButton optFillStyle 
  514.          Caption         =   "vbDownwardDiagonal"
  515.          Height          =   255
  516.          Index           =   5
  517.          Left            =   120
  518.          TabIndex        =   17
  519.          Top             =   1440
  520.          Width           =   1910
  521.       End
  522.    End
  523.    Begin VB.TextBox txtDrawWidth 
  524.       Height          =   285
  525.       Left            =   840
  526.       MaxLength       =   1
  527.       TabIndex        =   14
  528.       Top             =   120
  529.       Width           =   615
  530.    End
  531.    Begin VB.Frame Frame1 
  532.       Caption         =   "DrawStyle"
  533.       Height          =   2295
  534.       Index           =   1
  535.       Left            =   0
  536.       TabIndex        =   2
  537.       Top             =   2880
  538.       Width           =   2295
  539.       Begin VB.OptionButton optDrawStyle 
  540.          Caption         =   "vbInsideSolid"
  541.          Height          =   255
  542.          Index           =   6
  543.          Left            =   120
  544.          TabIndex        =   13
  545.          Top             =   1680
  546.          Width           =   1455
  547.       End
  548.       Begin VB.OptionButton optDrawStyle 
  549.          Caption         =   "vbTransparent"
  550.          Height          =   255
  551.          Index           =   5
  552.          Left            =   120
  553.          TabIndex        =   12
  554.          Top             =   1440
  555.          Width           =   1455
  556.       End
  557.       Begin VB.OptionButton optDrawStyle 
  558.          Caption         =   "vbDashDotDot"
  559.          Height          =   255
  560.          Index           =   4
  561.          Left            =   120
  562.          TabIndex        =   11
  563.          Top             =   1200
  564.          Width           =   1455
  565.       End
  566.       Begin VB.OptionButton optDrawStyle 
  567.          Caption         =   "vbDashDot"
  568.          Height          =   255
  569.          Index           =   3
  570.          Left            =   120
  571.          TabIndex        =   10
  572.          Top             =   960
  573.          Width           =   1455
  574.       End
  575.       Begin VB.OptionButton optDrawStyle 
  576.          Caption         =   "vbDot"
  577.          Height          =   255
  578.          Index           =   2
  579.          Left            =   120
  580.          TabIndex        =   9
  581.          Top             =   720
  582.          Width           =   1455
  583.       End
  584.       Begin VB.OptionButton optDrawStyle 
  585.          Caption         =   "vbDash"
  586.          Height          =   255
  587.          Index           =   1
  588.          Left            =   120
  589.          TabIndex        =   8
  590.          Top             =   480
  591.          Width           =   1455
  592.       End
  593.       Begin VB.OptionButton optDrawStyle 
  594.          Caption         =   "vbSolid"
  595.          Height          =   255
  596.          Index           =   0
  597.          Left            =   120
  598.          TabIndex        =   7
  599.          Top             =   240
  600.          Width           =   1455
  601.       End
  602.    End
  603.    Begin VB.Frame Frame1 
  604.       Caption         =   "Object"
  605.       Height          =   1095
  606.       Index           =   0
  607.       Left            =   3240
  608.       TabIndex        =   1
  609.       Top             =   0
  610.       Width           =   1455
  611.       Begin VB.OptionButton optObject 
  612.          Caption         =   "Box"
  613.          Height          =   255
  614.          Index           =   1
  615.          Left            =   120
  616.          TabIndex        =   6
  617.          Top             =   480
  618.          Width           =   615
  619.       End
  620.       Begin VB.OptionButton optObject 
  621.          Caption         =   "Line"
  622.          Height          =   255
  623.          Index           =   0
  624.          Left            =   120
  625.          TabIndex        =   5
  626.          Top             =   240
  627.          Width           =   735
  628.       End
  629.       Begin VB.OptionButton optObject 
  630.          Caption         =   "Circle"
  631.          Height          =   255
  632.          Index           =   2
  633.          Left            =   120
  634.          TabIndex        =   4
  635.          Top             =   720
  636.          Width           =   735
  637.       End
  638.    End
  639.    Begin VB.PictureBox picCanvas 
  640.       Height          =   5055
  641.       Left            =   4800
  642.       ScaleHeight     =   333
  643.       ScaleMode       =   3  'Pixel
  644.       ScaleWidth      =   253
  645.       TabIndex        =   0
  646.       Top             =   120
  647.       Width           =   3855
  648.    End
  649.    Begin VB.Label Label1 
  650.       Caption         =   "Y Stretch"
  651.       Height          =   255
  652.       Index           =   3
  653.       Left            =   1680
  654.       TabIndex        =   51
  655.       Top             =   510
  656.       Width           =   855
  657.    End
  658.    Begin VB.Label Label1 
  659.       Caption         =   "X Stretch"
  660.       Height          =   255
  661.       Index           =   2
  662.       Left            =   1680
  663.       TabIndex        =   49
  664.       Top             =   150
  665.       Width           =   855
  666.    End
  667.    Begin VB.Label Label1 
  668.       Caption         =   "Rotation"
  669.       Height          =   255
  670.       Index           =   1
  671.       Left            =   0
  672.       TabIndex        =   47
  673.       Top             =   510
  674.       Width           =   855
  675.    End
  676.    Begin VB.Label Label1 
  677.       Caption         =   "DrawWidth"
  678.       Height          =   255
  679.       Index           =   0
  680.       Left            =   0
  681.       TabIndex        =   3
  682.       Top             =   150
  683.       Width           =   855
  684.    End
  685.    Begin VB.Menu mnuFile 
  686.       Caption         =   "&File"
  687.       Begin VB.Menu mnuFileNew 
  688.          Caption         =   "&New"
  689.          Shortcut        =   ^N
  690.       End
  691.       Begin VB.Menu mnuFileOpen 
  692.          Caption         =   "&Open..."
  693.          Shortcut        =   ^O
  694.       End
  695.       Begin VB.Menu mnuFileSave2D 
  696.          Caption         =   "Save &2D File..."
  697.          Shortcut        =   ^S
  698.       End
  699.       Begin VB.Menu mnuFileSaveMetafile 
  700.          Caption         =   "Save &Metafile..."
  701.       End
  702.    End
  703.    Begin VB.Menu mnuEdit 
  704.       Caption         =   "&Edit"
  705.       Begin VB.Menu mnuEditUndo 
  706.          Caption         =   "&Undo"
  707.          Shortcut        =   ^Z
  708.       End
  709.       Begin VB.Menu mnuEditRedo 
  710.          Caption         =   "&Redo"
  711.          Shortcut        =   ^Y
  712.       End
  713.    End
  714. Attribute VB_Name = "frmStyles2D"
  715. Attribute VB_GlobalNameSpace = False
  716. Attribute VB_Creatable = False
  717. Attribute VB_PredeclaredId = True
  718. Attribute VB_Exposed = False
  719. Option Explicit
  720. Private TheScene As TwoDObject
  721. Private Enum ObjectTypes
  722.     objLine = 0
  723.     objBox = 1
  724.     objCircle = 2
  725. End Enum
  726. Private ObjectType As ObjectTypes
  727. Private Rubberbanding As Boolean
  728. Private OldMode As Integer
  729. Private OldStyle As Integer
  730. Private FirstX As Single
  731. Private FirstY As Single
  732. Private LastX As Single
  733. Private LastY As Single
  734. Private Declare Function CreateMetaFile Lib "gdi32" Alias "CreateMetaFileA" (ByVal lpString As String) As Long
  735. Private Declare Function CloseMetaFile Lib "gdi32" (ByVal hmf As Long) As Long
  736. Private Declare Function DeleteMetaFile Lib "gdi32" (ByVal hmf As Long) As Long
  737. Private Declare Function SetWindowExtEx Lib "gdi32" (ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, lpSize As SIZE) As Long
  738. Private Type SIZE
  739.     cx As Long
  740.     cy As Long
  741. End Type
  742. ' Currently selected drawing properties.
  743. Private CurrentDrawWidth As Integer
  744. Private CurrentDrawStyle As DrawStyleConstants
  745. Private CurrentForeColor As OLE_COLOR
  746. Private CurrentFillColor As OLE_COLOR
  747. Private CurrentFillStyle As FillStyleConstants
  748. ' Undo variables.
  749. Private Const MAX_UNDO = 50
  750. Private Snapshots As Collection
  751. Private CurrentSnapshot As Integer
  752. ' Save a snapshot for undo.
  753. Private Sub SaveSnapshot()
  754.     ' Remove any previously undone snapshots.
  755.     Do While Snapshots.Count > CurrentSnapshot
  756.         Snapshots.Remove Snapshots.Count
  757.     Loop
  758.     ' Save the current snapshot.
  759.     Snapshots.Add TheScene.Serialization
  760.     If m_Snapshots.Count > MAX_UNDO + 1 Then
  761.         Snapshots.Remove 1
  762.     End If
  763.     CurrentSnapshot = Snapshots.Count
  764.     ' Enable/disable the undo and redo menus.
  765.     SetUndoMenus
  766. End Sub
  767. ' Enable or disable the undo and redo menus.
  768. Private Sub SetUndoMenus()
  769.     mnuEditUndo.Enabled = (CurrentSnapshot > 1)
  770.     mnuEditRedo.Enabled = (CurrentSnapshot < Snapshots.Count)
  771. End Sub
  772. ' Restore the previous snapshot.
  773. Private Sub Undo()
  774.     If CurrentSnapshot <= 1 Then Exit Sub
  775.     ' Restore the previous snapshot.
  776.     CurrentSnapshot = CurrentSnapshot - 1
  777.     TheScene.Serialization = Snapshots(CurrentSnapshot)
  778.     ' Display the scene.
  779.     picCanvas.Refresh
  780.     ' Enable/disable the undo and redo menus.
  781.     SetUndoMenus
  782. End Sub
  783. ' Reapply a previously undone snapshot.
  784. Private Sub Redo()
  785.     If CurrentSnapshot >= Snapshots.Count Then Exit Sub
  786.     ' Restore the previous snapshot.
  787.     CurrentSnapshot = CurrentSnapshot + 1
  788.     TheScene.Serialization = Snapshots(CurrentSnapshot)
  789.     ' Display the scene.
  790.     picCanvas.Refresh
  791.     ' Enable/disable the undo and redo menus.
  792.     SetUndoMenus
  793. End Sub
  794. Private Sub mnuEditRedo_Click()
  795.     Redo
  796. End Sub
  797. Private Sub mnuEditUndo_Click()
  798.     Undo
  799. End Sub
  800. Private Sub mnuFileNew_Click()
  801.     Set TheScene = New TwoDScene
  802.     ' Display the scene.
  803.     picCanvas.Refresh
  804. End Sub
  805. Private Sub mnuFileOpen_Click()
  806. Dim file_name As String
  807. Dim fnum As Integer
  808. Dim the_serialization As String
  809. Dim token_name As String
  810. Dim token_value As String
  811.     ' Allow the user to pick a file.
  812.     On Error Resume Next
  813.     dlgFile.Filter = "2D Files (*.2d)|*.2d|" & _
  814.         "All Files (*.*)|*.*"
  815.     dlgFile.Flags = cdlOFNExplorer Or _
  816.         cdlOFNFileMustExist Or _
  817.         cdlOFNHideReadOnly Or _
  818.         cdlOFNLongNames
  819.     dlgFile.ShowOpen
  820.     If Err.Number = cdlCancel Then
  821.         Unload dlgFile
  822.         Exit Sub
  823.     ElseIf Err.Number <> 0 Then
  824.         Unload dlgFile
  825.         Beep
  826.         MsgBox "Error selecting file.", , vbExclamation
  827.         Exit Sub
  828.     End If
  829.     On Error GoTo 0
  830.     ' Read the picture's serialization.
  831.     file_name = dlgFile.FileName
  832.     fnum = FreeFile
  833.     Open file_name For Input As #fnum
  834.     the_serialization = RemoveNonPrintables(Input$(LOF(fnum), fnum))
  835.     Close fnum
  836.     ' Make sure this is a TwoDScene serialization.
  837.     GetNamedToken the_serialization, token_name, token_value
  838.     If token_name <> "TwoDScene" Then
  839.         ' This is not a valid serialization.
  840.         MsgBox "This is not a valid TwoDScene serialization."
  841.     Else
  842.         Caption = "Show2D [" & dlgFile.FileTitle & "]"
  843.         dlgFile.InitDir = Left$(file_name, Len(file_name) _
  844.             - Len(dlgFile.FileTitle) - 1)
  845.         ' Initialize the new scene.
  846.         Set TheScene = New TwoDScene
  847.         TheScene.Serialization = token_value
  848.     End If
  849.     ' Display the scene.
  850.     picCanvas.Refresh
  851. End Sub
  852. ' Save the object serialization.
  853. Private Sub mnuFileSave2D_Click()
  854. Dim file_name As String
  855. Dim fnum As Integer
  856.     If TheScene Is Nothing Then
  857.         MsgBox "No scene is loaded."
  858.         Exit Sub
  859.     End If
  860.     ' Allow the user to pick a file.
  861.     On Error Resume Next
  862.     dlgFile.Filter = _
  863.         "2D Files (*.2d)|*.2d|" & _
  864.         "All Files (*.*)|*.*"
  865.     dlgFile.Flags = _
  866.         cdlOFNOverwritePrompt Or _
  867.         cdlOFNPathMustExist Or _
  868.         cdlOFNHideReadOnly
  869.     dlgFile.ShowSave
  870.     If Err.Number = cdlCancel Then
  871.         ' The user canceled.
  872.         Unload dlgFile
  873.         Exit Sub
  874.     ElseIf Err.Number <> 0 Then
  875.         ' Unknown error.
  876.         Unload dlgFile
  877.         MsgBox "Error " & Format$(Err.Number) & _
  878.             " selecting file." & vbCrLf & _
  879.             Err.Description, vbExclamation
  880.         Exit Sub
  881.     End If
  882.     On Error GoTo Save2DFileError
  883.     ' Get the file name.
  884.     file_name = dlgFile.FileName
  885.     dlgFile.InitDir = Left$(file_name, Len(file_name) _
  886.         - Len(dlgFile.FileTitle) - 1)
  887.     Caption = "Show2D [" & dlgFile.FileTitle & "]"
  888.     ' Open the file.
  889.     fnum = FreeFile
  890.     Open file_name For Output As fnum
  891.     ' Write the serialization into the file.
  892.     Print #fnum, TheScene.Serialization
  893.     ' Close the file.
  894.     Close fnum
  895.     Exit Sub
  896. Save2DFileError:
  897.     MsgBox "Error " & Format$(Err.Number) & _
  898.         " saving file." & vbCrLf & _
  899.         Err.Description, vbExclamation
  900.     Exit Sub
  901. End Sub
  902. ' Draw an ellipse bounded by a rectangle.
  903. Private Sub DrawEllipse(ByVal obj As Object, ByVal xmin As Single, ByVal ymin As Single, ByVal xmax As Single, ByVal ymax As Single)
  904. Dim cx As Single
  905. Dim cy As Single
  906. Dim wid As Single
  907. Dim hgt As Single
  908. Dim aspect As Single
  909. Dim Radius As Single
  910.     ' Find the center.
  911.     cx = (xmin + xmax) / 2
  912.     cy = (ymin + ymax) / 2
  913.     ' Get the ellipse's size.
  914.     wid = Abs(xmax - xmin)
  915.     hgt = Abs(ymax - ymin)
  916.     ' Do nothing if the width or height is zero.
  917.     If (wid = 0) Or (hgt = 0) Then Exit Sub
  918.     aspect = hgt / wid
  919.     ' See which dimension is larger.
  920.     If wid > hgt Then
  921.         ' The major axis is horizontal.
  922.         ' Get the radius in custom coordinates.
  923.         Radius = wid / 2
  924.     Else
  925.         ' The major axis is vertical.
  926.         ' Get the radius in custom coordinates.
  927.         Radius = hgt / 2
  928.     End If
  929.     ' Draw the circle.
  930.     obj.Circle (cx, cy), Radius, , , , aspect
  931. End Sub
  932. ' Draw the appropriate object.
  933. Private Sub DrawObject(ByVal xmin As Single, ByVal ymin As Single, ByVal xmax As Single, ByVal ymax As Single)
  934.     Select Case ObjectType
  935.         Case objLine
  936.             picCanvas.Line (xmin, ymin)-(xmax, ymax)
  937.         Case objBox
  938.             picCanvas.Line (xmin, ymin)-(xmax, ymax), , B
  939.         Case objCircle
  940.             DrawEllipse picCanvas, xmin, ymin, xmax, ymax
  941.     End Select
  942. End Sub
  943. ' Create the appropriate object and redraw.
  944. Private Sub Create2DObject(ByVal xmin As Single, ByVal ymin As Single, ByVal xmax As Single, ByVal ymax As Single)
  945. Const PI = 3.14159265
  946. Dim obj As TwoDObject
  947. Dim obj_line As TwoDLine
  948. Dim obj_rectangle As TwoDRectangle
  949. Dim obj_ellipse As TwoDEllipse
  950. Dim obj_scene As TwoDScene
  951. Dim M(1 To 3, 1 To 3) As Single
  952.     ' Create the new object.
  953.     Select Case ObjectType
  954.         Case objLine
  955.             Set obj = New TwoDLine
  956.             Set obj_line = obj
  957.             obj_line.X1 = xmin
  958.             obj_line.X2 = xmax
  959.             obj_line.Y1 = ymin
  960.             obj_line.Y2 = ymax
  961.         Case objBox
  962.             Set obj = New TwoDRectangle
  963.             Set obj_rectangle = obj
  964.             obj_rectangle.X1 = xmin
  965.             obj_rectangle.X2 = xmax
  966.             obj_rectangle.Y1 = ymin
  967.             obj_rectangle.Y2 = ymax
  968.         Case objCircle
  969.             Set obj = New TwoDEllipse
  970.             Set obj_ellipse = obj
  971.             obj_ellipse.X1 = xmin
  972.             obj_ellipse.X2 = xmax
  973.             obj_ellipse.Y1 = ymin
  974.             obj_ellipse.Y2 = ymax
  975.             obj_ellipse.X1 = xmin
  976.     End Select
  977.     ' Set the new object's drawing properties.
  978.     obj.DrawWidth = CurrentDrawWidth
  979.     obj.DrawStyle = CurrentDrawStyle
  980.     obj.ForeColor = CurrentForeColor
  981.     obj.FillColor = CurrentFillColor
  982.     obj.FillStyle = CurrentFillStyle
  983.     ' Add the object to the scene.
  984.     Set obj_scene = TheScene
  985.     obj_scene.SceneObjects.Add obj
  986.     ' Save the current scene.
  987.     SaveSnapshot
  988.     ' Display the scene.
  989.     picCanvas.Refresh
  990. End Sub
  991. ' Make the canvas as big as possible.
  992. Private Sub Form_Resize()
  993. Dim wid As Single
  994.     wid = ScaleWidth - picCanvas.Left
  995.     If wid < 120 Then wid = 120
  996.     picCanvas.Move picCanvas.Left, 0, wid, ScaleHeight
  997. End Sub
  998. Private Sub mnuFileSaveMetafile_Click()
  999. Dim file_name As String
  1000. Dim mf_dc As Long
  1001. Dim hmf As Long
  1002. Dim old_size As SIZE
  1003.     If TheScene Is Nothing Then
  1004.         MsgBox "No scene is loaded."
  1005.         Exit Sub
  1006.     End If
  1007.     ' Allow the user to pick a file.
  1008.     On Error Resume Next
  1009.     dlgFile.Filter = _
  1010.         "Metafiles (*.wmf)|*.wmf|" & _
  1011.         "All Files (*.*)|*.*"
  1012.     dlgFile.Flags = _
  1013.         cdlOFNOverwritePrompt Or _
  1014.         cdlOFNPathMustExist Or _
  1015.         cdlOFNHideReadOnly
  1016.     dlgFile.ShowSave
  1017.     If Err.Number = cdlCancel Then
  1018.         ' The user canceled.
  1019.         Unload dlgFile
  1020.         Exit Sub
  1021.     ElseIf Err.Number <> 0 Then
  1022.         ' Unknown error.
  1023.         Unload dlgFile
  1024.         MsgBox "Error " & Format$(Err.Number) & _
  1025.             " selecting file." & vbCrLf & _
  1026.             Err.Description, vbExclamation
  1027.         Exit Sub
  1028.     End If
  1029.     On Error GoTo SaveMetafileError
  1030.     ' Get the file name.
  1031.     file_name = dlgFile.FileName
  1032.     dlgFile.InitDir = Left$(file_name, Len(file_name) _
  1033.         - Len(dlgFile.FileTitle) - 1)
  1034.     Caption = "Show2D [" & dlgFile.FileTitle & "]"
  1035.     ' Create the metafile.
  1036.     mf_dc = CreateMetaFile(ByVal file_name)
  1037.     If mf_dc = 0 Then
  1038.         MsgBox "Error creating the metafile.", vbExclamation
  1039.         Exit Sub
  1040.     End If
  1041.     ' Set the metafile's size to something reasonable.
  1042.     SetWindowExtEx mf_dc, picCanvas.ScaleWidth, _
  1043.         picCanvas.ScaleHeight, old_size
  1044.     ' Draw in the metafile.
  1045.     TheScene.DrawInMetafile mf_dc
  1046.     ' Close the metafile.
  1047.     hmf = CloseMetaFile(mf_dc)
  1048.     If hmf = 0 Then
  1049.         MsgBox "Error closing the metafile.", vbExclamation
  1050.     End If
  1051.     ' Delete the metafile to free resources.
  1052.     If DeleteMetaFile(hmf) = 0 Then
  1053.         MsgBox "Error deleting the metafile.", vbExclamation
  1054.     End If
  1055.     Exit Sub
  1056. SaveMetafileError:
  1057.     MsgBox "Error " & Format$(Err.Number) & _
  1058.         " saving file." & vbCrLf & _
  1059.         Err.Description, vbExclamation
  1060.     Exit Sub
  1061. End Sub
  1062. ' Set the DrawStyle.
  1063. Private Sub optDrawStyle_Click(Index As Integer)
  1064.     CurrentDrawStyle = Index
  1065. End Sub
  1066. ' Set the FillColor.
  1067. Private Sub optFillColor_Click(Index As Integer)
  1068.     CurrentFillColor = optFillColor(Index).ForeColor
  1069. End Sub
  1070. ' Set the FillStyle.
  1071. Private Sub optFillStyle_Click(Index As Integer)
  1072.     CurrentFillStyle = Index
  1073. End Sub
  1074. ' Start a rubberbanding of some sort.
  1075. Private Sub picCanvas_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  1076.     ' Let MouseMove know we are rubberbanding.
  1077.     Rubberbanding = True
  1078.     ' Save values so we can restore them later.
  1079.     OldMode = picCanvas.DrawMode
  1080.     OldStyle = picCanvas.DrawStyle
  1081.     picCanvas.DrawMode = vbInvert
  1082.     If ObjectType = objLine Then
  1083.         picCanvas.DrawStyle = vbSolid
  1084.     Else
  1085.         picCanvas.DrawStyle = vbDot
  1086.     End If
  1087.     ' Save the starting coordinates.
  1088.     FirstX = X
  1089.     FirstY = Y
  1090.     ' Save the ending coordinates.
  1091.     LastX = X
  1092.     LastY = Y
  1093.     ' Draw the appropriate rubberband object.
  1094.     DrawObject FirstX, FirstY, LastX, LastY
  1095. End Sub
  1096. ' Continue rubberbanding.
  1097. Private Sub picCanvas_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  1098.     ' If we are not rubberbanding, do nothing.
  1099.     If Not Rubberbanding Then Exit Sub
  1100.     ' Erase the previous rubberband object.
  1101.     DrawObject FirstX, FirstY, LastX, LastY
  1102.     ' Save the new ending coordinates.
  1103.     LastX = X
  1104.     LastY = Y
  1105.     ' Draw the new rubberband object.
  1106.     DrawObject FirstX, FirstY, LastX, LastY
  1107. End Sub
  1108. ' Finish rubberbanding and draw the object.
  1109. Private Sub picCanvas_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  1110.     ' If we are not rubberbanding, do nothing.
  1111.     If Not Rubberbanding Then Exit Sub
  1112.     ' We are no longer rubberbanding.
  1113.     Rubberbanding = False
  1114.     ' Erase the previous rubberband object.
  1115.     DrawObject FirstX, FirstY, LastX, LastY
  1116.     ' Restore the original DrawMode and DrawStyle.
  1117.     picCanvas.DrawMode = OldMode
  1118.     picCanvas.DrawStyle = OldStyle
  1119.     ' Create the final object.
  1120.     Create2DObject FirstX, FirstY, LastX, LastY
  1121. End Sub
  1122. ' Select the default options.
  1123. Private Sub Form_Load()
  1124.     optForeColor(0).Value = True
  1125.     optFillColor(0).Value = True
  1126.     optDrawStyle(vbSolid).Value = True
  1127.     optFillStyle(vbFSTransparent).Value = True
  1128.     txtDrawWidth.Text = Format$(picCanvas.DrawWidth)
  1129.     optObject(ObjectType).Value = True
  1130.     ' Initialize the common dialog.
  1131.     dlgFile.InitDir = App.Path
  1132.     dlgFile.CancelError = True
  1133.     ' Create an empty scene.
  1134.     Set TheScene = New TwoDScene
  1135.     ' Save the initial, empty snapshot.
  1136.     Set Snapshots = New Collection
  1137.     SaveSnapshot
  1138. End Sub
  1139. ' Record the kind of object to draw next.
  1140. Private Sub optObject_Click(Index As Integer)
  1141.     ObjectType = Index
  1142. End Sub
  1143. ' Set the ForeColor.
  1144. Private Sub optForeColor_Click(Index As Integer)
  1145.     CurrentForeColor = optForeColor(Index).ForeColor
  1146. End Sub
  1147. Private Sub picCanvas_Paint()
  1148.     picCanvas.Cls
  1149.     If Not TheScene Is Nothing Then TheScene.Draw picCanvas
  1150. End Sub
  1151. ' Change set DrawWidth.
  1152. Private Sub txtDrawWidth_Change()
  1153. Dim wid As Integer
  1154.     If Not IsNumeric(txtDrawWidth.Text) Then Exit Sub
  1155.     wid = CInt(txtDrawWidth.Text)
  1156.     If wid < 1 Then Exit Sub
  1157.     CurrentDrawWidth = wid
  1158. End Sub
  1159. ' Only allow 1 through 9.
  1160. Private Sub txtDrawWidth_KeyPress(KeyAscii As Integer)
  1161.     If KeyAscii < Asc(" ") Or _
  1162.        KeyAscii > Asc("~") Then Exit Sub
  1163.     If KeyAscii >= Asc("1") And _
  1164.        KeyAscii <= Asc("9") Then Exit Sub
  1165.     Beep
  1166.     KeyAscii = 0
  1167. End Sub
  1168.